package com.sbpm.crmbpm.server.mgmt.impl;

import com.sbpm.crmbpm.client.services.DictionaryManagement;
import com.sbpm.crmbpm.server.dao.DictionaryDao;
import com.sbpm.crmbpm.server.utils.JpaUtils;
import com.sbpm.crmbpm.shared.data.client.Company;
import com.sbpm.crmbpm.shared.data.dict.City;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service( "dictionaryManagement" )
@Transactional( propagation = Propagation.REQUIRED )
public class DictionaryManagementImpl implements DictionaryManagement
{
    private static final Logger log = LoggerFactory.getLogger( DictionaryManagementImpl.class );

    @Autowired
    private DictionaryDao dictionaryDao;

    public List<City> getCitiesWithCountries()
    {
        JpaUtils utils = new JpaUtils();
        try
        {
            return ( List ) utils.cloneObjectAndDetach( dictionaryDao.getCitiesWithCountries() );
        }
        catch ( IllegalAccessException | InstantiationException e )
        {
            log.error( "", e );
        }
        return null;
    }
}
